from django.db import models

class Order(models.Model):
    order_id = models.IntegerField(primary_key=True, blank=True, db_comment='订单ID')
    customer = models.CharField(max_length=255, blank=True, null=True, db_comment='客户名称')
    order_date = models.DateField(blank=True, null=True, db_comment='下单日期')
    status = models.IntegerField(max_length=255, blank=True, null=True, db_comment='订单状态')
    remarks = models.CharField(max_length=255, blank=True, null=True, db_comment='备注')

    class Meta:
        db_table = 'order'


class OrderDetail(models.Model):
    detail_id = models.AutoField(primary_key=True, db_comment='明细ID')
    order_id = models.ForeignKey(to='Order',
                                      on_delete=models.CASCADE,
                                      related_name='detail',
                                      db_comment='订单ID',
                                      db_index=True,
                                      to_field='order_id',
                                      db_column='order_id')
    product_id = models.IntegerField(blank=True, null=True, db_comment='产品ID')
    product_name = models.CharField(max_length=255,blank=True, null=True, db_comment='产品名称')
    quantity = models.IntegerField(max_length=255, blank=True, null=True, db_comment='产品数量')

    class Meta:
        db_table = 'order_detail'